import {reqGoodsInfo,reqAddOrUpdateShopCart} from '@/api'
import { getUUID } from '@/utils/uuid_token';
const state = {
    goodInfo:{},
    //游客临时身份
    uuid_token:getUUID()
};
const mutations = {
    GETGOODINFO(state,goodInfo){
        state.goodInfo=goodInfo
    } 
}
const actions = {
    //获取search模块数据
    async getGoodInfo({commit},skuId){
        let result= await reqGoodsInfo(skuId)
        //console.log('1111',result);
        if(result.code ==200){
            commit('GETGOODINFO',result.data)
        }
    },
    //将产品添加到购物车中
    async addOrUpdateShopCart({commit},{skuId,skuNum}){
        let result= await reqAddOrUpdateShopCart(skuId,skuNum)
        //console.log('1111',result);
        if(result.code ==200){
            // //console.log({commit});
            return "ok";
            // commit('GETGOODINFO',result.data)
        }else{
            return Promise.reject(new Error('faile'))
        }
    }
}
const getters = {
    categoryView(state){
         return state.goodInfo.categoryView||{}
    },
    skuInfo(state){
        return state.goodInfo.skuInfo||{}
   },
   spuSaleAttrList(state){
    return state.goodInfo.spuSaleAttrList||[]
},
}
export default {
    state,
    mutations,
    actions,
    getters,
}